/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mh.bol;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import mh.dal.DAO;
import mh.entity.ComplaintEn;
import mh.entity.StatisticEn;

/**
 *
 * @author VIETNH
 */
public class AdminStatisticBO {

    DAO dao = new DAO();

    public ArrayList<StatisticEn> getStatisticBySince(String typeView, String startDate, String endDate) {
        ArrayList<StatisticEn> listStatistic = new ArrayList<StatisticEn>();
        Properties p = new Properties();
        p.put(1, typeView);
        p.put(2, startDate);
        p.put(3, endDate);
        try {
            ResultSet rs = (ResultSet) dao.executeProc("sp_StatisticComplaint", p, "query");

            while (rs.next()) {
                StatisticEn ce = new StatisticEn();
                int type = rs.getInt("C_Type");
                if (type == 1) {
                    ce.setTypeString("Facilities");
                } else if (type == 2) {
                    ce.setTypeString("Wage");
                } else if (type == 3) {
                    ce.setTypeString("Other issues");
                }
                ce.setType(type);
                ce.setTotal(rs.getInt("Total"));
                listStatistic.add(ce);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return listStatistic;
    }
    
    public ArrayList<StatisticEn> getStatisticByTypeComp(String typeComp) {
        ArrayList<StatisticEn> listStatistic = new ArrayList<StatisticEn>();
        Properties p = new Properties();
        p.put(1, typeComp);
        try {
            ResultSet rs = (ResultSet) dao.executeProc("sp_ViewStatisticByTypeComp", p, "query");

            while (rs.next()) {
                StatisticEn ce = new StatisticEn();
                ce.setTypeString(rs.getString("D_Name"));
                ce.setTotal(rs.getInt("Total"));
                listStatistic.add(ce);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return listStatistic;
    }
}
